﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Windows;

namespace WaterForecast.manager
{
    public class XmlConfigManager
    {
        public static XmlConfigManager Man = new XmlConfigManager();

        public String GetRHFSPath()
        {
            return GetConfigNodeValue("/root/RHFSFilePath");
        }

        public String GetFlowDataPath()
        {
            return GetConfigNodeValue("/root/原始文件路径");
        }

        public String GetExerciseDataPath()
        {
            return GetConfigNodeValue("/root/RHFSFilePath") + GetConfigNodeValue("/root/BP网络训练路径");
        }

        public String GetSaveDataPath()
        {
            return GetConfigNodeValue("/root/RHFSFilePath") + GetConfigNodeValue("/root/BP网络保存路径");
        }

        String GetConfigNodeValue(String xmlpath)
        {
            XmlDocument xml = new XmlDocument();
            xml.Load(Environment.CurrentDirectory + "//Config.xml");
            XmlNodeList nodelist = xml.SelectNodes(xmlpath);
            return nodelist[0].InnerText;
        }

        public String GetPlaceFilePath(String placename)
        {
            String Path = "";
            XmlDocument xml = new XmlDocument();
            xml.Load(Environment.CurrentDirectory + "//Config.xml");
            XmlNodeList nodelist = xml.SelectNodes("//" + placename + "//文件路径");
            if (nodelist.Count > 0)
            {
                Path = GetRHFSPath() + GetFlowDataPath() + nodelist[0].InnerText;
            }
            return Path;
        }

        public int GetPlaceColumnNum(String placename)
        {
            int num = 0;
            XmlDocument xml = new XmlDocument();
            xml.Load(Environment.CurrentDirectory + "//Config.xml");
            XmlNodeList nodelist = xml.SelectNodes("//" + placename + "//列数");
            num = Convert.ToInt32(nodelist[0].InnerText);
            return num;
        }
    }
}
